#include <stdio.h>

typedef struct
{
    int X;
    int Y;
} vector;

int main()
{
    int n;
    scanf("%d", &n);
    int cube[n][n];

    for (int y = 0; y < n; y++)
    {
        for (int x = 0; x < n; x++)
        {
            cube[y][x] = 0;
        }
    }

    int i = 0, j = 0, next_i = 0, next_j = 1;
    cube[i][j] = 1;

    vector direction[4] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    int turn = 0; // 当前方向

    for (int k = 2; k <= n * n; k++)
    {

        next_i = i + direction[turn].X;
        next_j = j + direction[turn].Y;

        if (next_i >= n || next_i < 0 || next_j >= n || next_j < 0 || cube[next_i][next_j] != 0)
        {
            turn = (turn + 1) % 4;
            next_i = i + direction[turn].X;
            next_j = j + direction[turn].Y;
        }
        i = next_i;
        j = next_j;
        cube[i][j] = k;
    }

    for (int y = 0; y < n; y++)
    {
        for (int x = 0; x < n; x++)
        {
            printf("%5d", cube[y][x]);
        }
        printf("\n");
    }

    return 0;
}
